<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>WinA</title>
    <link rel="stylesheet" type="text/css" href="css/api.css" />
    <link rel="stylesheet" type="text/css" href="css/box.css" />
    <script type="text/javascript" src="script/public.js"></script>
    <style>
    	p{
    		color:#999;
    		padding:5px;
    	}
    </style>
	<script type="text/javascript">
	    
		var uzmoduledemo = null;
		var scrollPicture = null;
		var leidenSDK = null;
		apiready = function(){
	    	uzmoduledemo = api.require('moduleDemo');
	    	scrollPicture = api.require('scrollPicture');
			leidenSDK = api.require('leidenSDK');
			leidenSDK.init(function(ret,err) {
			});
	    }

	    function testApi() {
			api.openWin({
      	  		name: 'connect',
        		url: './connect.html',
        		pageParam: {
            		name: 'test'
        		}
    		});
	    }

function printf() {
	var json = {
			"labels":[
				{
					"labelW":50 * 8,//标签的宽度 50的单位mm，8 为打印机上 mm 与 px的转化单位。必须
					"labelH":50 * 8,//同标签宽度。必须
					"number":1,// 打印的张数。不必须 默认为1
					"bitmaps":[// 打印的图片数据。不必须。没有数据则打印一张空白标签
						{
							"x":0 * 8,//同标签宽度。当前图片的x坐标。必须
							"y":0 * 8,//同标签宽度。当前图片的x坐标。必须
							"WD":25 * 8,//同标签宽度。当前图片的宽度。必须
							"HT":25 * 8,//同标签宽度。当前图片的高度。必须
							"bitmapPath":"/storage/emulated/0/logo.png"// 图片路径。必须
						}
					]
				},{
					"labelW":50 * 8,//标签的宽度 50的单位mm，8 为打印机上 mm 与 px的转化单位。必须
					"labelH":100 * 8,//同标签宽度。必须
					"number":2,// 打印的张数。不必须 默认为1
					"bitmaps":[// 打印的图片数据。不必须。没有数据则打印一张空白标签
						{
							"x":0 * 8,//同标签宽度。当前图片的x坐标。必须
							"y":0 * 8,//同标签宽度。当前图片的x坐标。必须
							"WD":30 * 8,//同标签宽度。当前图片的宽度。必须
							"HT":30 * 8,//同标签宽度。当前图片的高度。必须
							"bitmapPath":"/storage/emulated/0/logo.png"// 图片路径必须
						}
					]
				}
			]
		};
	leidenSDK.printfLabels(json,function(ret,err) {
		console.log(JSON.stringify(ret));
	})
}

function setCurrentEnvContinue() {
	leidenSDK.getCurrentEnviron(function(ret,err){
		console.log(JSON.stringify(ret));
		ret.labelType = 3;
		leidenSDK.setCurrentEnviron(ret,function(ret,err){
			alert(JSON.stringify(ret));
		});
	})
}

function setCurrentEnvLabel() {
	leidenSDK.getCurrentEnviron(function(ret,err){
		ret.labelType = 2;
		leidenSDK.setCurrentEnviron(ret,function(ret,err){
			alert(JSON.stringify(ret));
		});
	})
}

		function isConnect() {
leidenSDK.isConnect(function(ret,err) {
	alert(JSON.stringify(ret));
});
		}

		function showAlert(){
			var param = {msg:"Hello APICloud!"};
	        uzmoduledemo.showAlert(param, function(ret, err){
	        	alert(JSON.stringify(ret));
	        });
		}

		function writerString() {
var json = {"content":"JOB\nDEF PW=560,PH=640\nSTART\nQTY P=1\nEND\nJOBE\n"};
leidenSDK.writer(json,function(ret,err) {
	if (ret.result == 1) {
		alert("发送成功");
	} else {
		alert("发送失败");
	}
})
		}

		function closeConnect() {
			leidenSDK.closeConnect();
		}


		var sModule = null;
		
		function syncInterface(what){
			if(!sModule){
				sModule = api.require('syncModule');
			}
			var ret = null;
			if(0 == what){
				ret = sModule.int();
			}else if(1 == what){
				ret = sModule.float();
			}else if(2 == what){
				ret = sModule.boolean();
			}else if(3 == what){
				ret = sModule.string();
			}else if(4 == what){
				ret = sModule.json();
			}else if(5 == what){
				ret = sModule.jsonay();
			}else{
				return;
			}
			if(typeof ret === 'object'){
				alert("获取结果为对象！\n结果：" + JSON.stringify(ret));
			}else{
				alert("获取结果为基本数据!\n结果：" + ret);
			}
		}
	    
	</script>
</head>
<body>
    <div id="wrap">
        <div id="main">
        	<br>
			<div class="clickbtn" style="margin:20px;" tapmode="active" onclick="testApi()" >连接设备</div>

			<div class="clickbtn" style="margin:20px;" tapmode="active" onclick="printf()" >打印</div>

			<div class="clickbtn" style="margin:20px;" tapmode="active" onclick="setCurrentEnvContinue()">设置环境变量(连续纸)</div>
			<div class="clickbtn" style="margin:20px;" tapmode="active" onclick="setCurrentEnvLabel()">设置环境变量(标签纸)</div>

			<div class="clickbtn" style="margin:20px;" tapmode="active" onclick="isConnect()">是否连接</div>

			<div class="clickbtn" style="margin:20px;" tapmode="active" onclick="writerString()">写文本</div>

			<div class="clickbtn" style="margin:20px;" tapmode="active" onclick="closeConnect()">关闭</div>

		</div>
	</div>
</body>
</html>